import RNFetchBlob from 'rn-fetch-blob'

export function path2base64(path){
    return new Promise((resolve,reject)=>{
        if(path){
            let data = "";
            RNFetchBlob.fs.readStream(
                path,
            'base64',
            )
            .then((ifstream) => {
                ifstream.open()
                ifstream.onData((chunk) => {
                    data += chunk
                })
                ifstream.onError((err) => {
                    reject(err);
                })
                ifstream.onEnd(() => {  
                    resolve(data);
                })
            })
        }else{
            //适配一下修改分类时候图片为null情况
            resolve(null);
        }
    })
}